﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using Mvc3Demo.Core;

namespace Mvc3Demo
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            Context.AuthenticationTicket();
        }

        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            /* Ignore static content, see 
             * http://weblogs.asp.net/rashid/archive/2009/04/03/asp-net-mvc-best-practices-part-2.aspx  
            */
            routes.RouteExistingFiles = false;
            routes.IgnoreRoute("Content/{*pathInfo}");
            routes.IgnoreRoute("Scripts/{*pathInfo}");
            routes.IgnoreRoute("Styles/{*pathInfo}");
            routes.IgnoreRoute("{*favicon}",
                new { favicon = @"(.*/)?favicon.([iI][cC][oO]|[gG][iI][fF])(/.*)?" });

            //Ignore handlers and resources 
            routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            var customSettins = ViewTypeSettings.Settings;
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            ViewEngines.Engines.Clear();

            ViewEngines.Engines.Add(new MobileViewEngine());

            Bootstrapper.Initialise();
        }
    }
}

#region Important notes
    /*
         * get latest jQuery from nuget
         * get latest jQuery.ui from nuget
         * get unity from nuget
         * get unit.mvc3 from nuget.org
         * get latest packege from HTML5 Boilerpalte (http://html5boilerplate.com/) (modernizr.js)
         * knockout.js for mvvm pattern in mvc
         * SVG (Scalble Vector Graphics) (w3school, raphaeljs.com js plugin)
         * canvas & (EaselJS, Fabric, Flot, Gury, JcanvasScript) js frameworks
         * google for HTML5 canvas Cheat Sheet
        */
#endregion